<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div></div>
    <img src="" alt="">
    <script>
        function getTime() {
            var date = new Date();
            var Year = date.getFullYear();
            var Month = date.getMonth() + 1;
            var Dates = date.getDate();
            var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
            var Day = date.getDay();
            var hour = date.getHours();
            var minute = date.getMinutes();

            var a = Year + '年' + Month + '月' + Dates + '日' + arr[Day] + ' ' + hour + '时' + minute + '分';
            return a;
        }
        var div = document.querySelector('div');
        div.innerHTML = getTime();

        var img = document.querySelector('img');
        var date = new Date();
        var time = date.getHours();
        console.log(time);
        if (24 >= time && time >= 23 || 0 <= time && time < 6) {
            img.src = 'images/z.gif';
            img.title = '早上好';
        } else if (time >= 6 && time < 12) {
            img.src = 'images/s.gif';
            img.title = '上午好';
        } else if (time >= 12 && time < 18) {
            img.src = 'images/x.gif';
            img.title = '下午好';
        } else if (time >= 18 && time < 23) {
            img.src = 'images/w.gif';
            img.title = '晚上好';
        }
    </script>
</body>

</html>